package com.neusoft.yiyang.medical.controller;

import com.neusoft.yiyang.common.entity.medical.CheckOrder;
import com.neusoft.yiyang.medical.service.CheckOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "检查医嘱管理接口", description = "负责检查医嘱的创建、查询、更新及删除操作")
@RestController
@RequestMapping("/check-orders")
public class CheckOrderController {

    @Autowired
    private CheckOrderService checkOrderService;

    @Operation(summary = "创建检查医嘱", description = "为客户新增检查医嘱（含检查项目、执行时间、医生信息等）")
    @PostMapping("/create")
    public void createCheckOrder(
            @Parameter(description = "检查医嘱信息（含客户ID、检查项目、医嘱内容等）", required = true)
            @RequestBody CheckOrder checkOrder) {
        checkOrderService.createCheckOrder(checkOrder);
    }

    @Operation(summary = "获取所有检查医嘱", description = "查询系统中所有的检查医嘱记录")
    @GetMapping("/all")
    public List<CheckOrder> getAllCheckOrders() {
        return checkOrderService.getAllCheckOrders();
    }

    @Operation(summary = "查询客户的检查医嘱", description = "获取指定客户的所有检查医嘱记录")
    @GetMapping("/customer/{customerId}")
    public List<CheckOrder> getCheckOrdersByCustomerId(
            @Parameter(description = "客户ID", required = true)
            @PathVariable Integer customerId) {
        return checkOrderService.getCheckOrdersByCustomerId(customerId);
    }

    @Operation(summary = "更新检查医嘱", description = "修改指定检查医嘱的信息（如执行状态、备注等）")
    @PutMapping("/update/{checkOrderId}")
    public void updateCheckOrder(
            @Parameter(description = "检查医嘱ID", required = true) @PathVariable Integer checkOrderId,
            @Parameter(description = "更新后的检查医嘱信息", required = true) @RequestBody CheckOrder checkOrder) {
        checkOrder.setCheckOrderId(checkOrderId);
        checkOrderService.updateCheckOrder(checkOrder);
    }

    @Operation(summary = "删除检查医嘱", description = "移除指定的检查医嘱记录")
    @DeleteMapping("/delete/{checkOrderId}")
    public void deleteCheckOrder(
            @Parameter(description = "检查医嘱ID", required = true) @PathVariable Integer checkOrderId) {
        checkOrderService.deleteCheckOrder(checkOrderId);
    }
}